package cn.zt.controller;


import cn.zt.common.Result;
import cn.zt.domain.Bankcard;
import cn.zt.service.BankcardService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("banckcard")
public class BankcardController {

    @Resource
    private BankcardService bankcardService;

    //通过用户名查询卡号
    @GetMapping("selectbyname")
    public Result selectByNickname(@RequestParam("name") String name) {
        Result result = bankcardService.selectByNickname(name);
        return result;
    }

    //添加银行卡
    @PostMapping("addbankcard")
    public int addBankcard(@RequestBody Bankcard bankcard) {
        return bankcardService.addBankcard(bankcard);
    }

    //通过银行卡号,姓名,预留电话查询
    @GetMapping("selectByThree")
    public Result selectByThree( Bankcard bankcard){
        return bankcardService.selectByThree(bankcard);
    }

    //根据登录人的名字查自己的银行卡号
    @GetMapping("/selectBankCardByName")
    public List<Bankcard> selectBankCardByName(String nickname){
        return bankcardService.selectBankCardByName(nickname);
    }

    //判断名字和银行卡号是否符合
    @GetMapping("/selectByBankCard")
    public List<Bankcard> selectByBankCardname(String nickname){
        return bankcardService.selectByBankCardname(nickname);
    }

    //根据nickname查询这个人有多少张银行卡
    @GetMapping("/cardAll")
    public Result cardAll(String nickname) {
        return bankcardService.getCardAll(nickname);
    }

    //openfeign(更具银行卡账号进行查询支付密码)
    @GetMapping("/getBankCard")
    public Bankcard getBankCard(@RequestParam("bankCard")String bankCard) {
        return bankcardService.getBankCard(bankCard);
    }

    //减余额
    @PostMapping("/jiBalance")
    public int jiBalance(@RequestParam("bankCard")String bankCard,@RequestParam("money")Integer money) {
        return bankcardService.jiBalance(bankCard,money);
    }

    //赎回
    @PostMapping("/jaBalance")
    public int jaBalance(@RequestParam("banCard")String bankCard,@RequestParam("money")Integer money){
        return bankcardService.jaBalance(bankCard,money);
    }


    //通过nickname查询银行卡
    @GetMapping("/selectBankCardByNickNameAndId")
    public Bankcard selectBankCardByNameId(@RequestParam("nickname") String nickname) {
        return bankcardService.selectBankCardByNickName(nickname);
    }

    //获取银行卡的主键
    @GetMapping("findId")
    public Integer findId(@RequestParam("bankCard")String bankCard){
        return bankcardService.findId(bankCard);
    }


    //我的账户
//    @GetMapping("/myCount")
//    public Result myCount(String nickname){
//        return bankcardService.myCount(nickname);
//    }


    //根据登录人nickname查询银行卡号以及余额
//    @GetMapping("/findBankcardBalance")
//    public Result findBankcardBalance(String nickname){
//        return bankcardService.findBankcardBalance(nickname);
//    }


    //根据nickname查询银行卡
    @GetMapping("/findCards")
    public Result findCards(String nickname){
        return bankcardService.findCards(nickname);
    }
}
